<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;

class LoginLogResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'username' => $this->username,
            'ip' => $this->ip,
            'user_agent' => $this->user_agent,
            'status' => $this->status,
            'message' => $this->message,
            'login_at' => $this->formatDateTime($this->login_at),
            'user' => $this->whenLoaded('user', function () {
                return [
                    'id' => $this->user->id,
                    'username' => $this->user->username,
                    'nickname' => $this->user->nickname,
                ];
            }),
            'created_at' => $this->formatDateTime($this->created_at),
            'updated_at' => $this->formatDateTime($this->updated_at),
        ];
    }
}

